/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.GroupManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class UpdateGroup extends AbstractAction
/*    */ {
/* 27 */   private static Logger logger = Logger.getLogger(UpdateGroup.class.getName());
/*    */ 
/* 29 */   private int id = 0;
/*    */ 
/*    */   public UpdateGroup(AbstractHttpServlet servlet) {
/* 32 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public UpdateGroup(AbstractHttpServlet servlet, String id) {
/* 36 */     super(servlet);
/* 37 */     this.id = Util.str2Int(id);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 43 */     User loginUser = super.getLoginUser(request);
/* 44 */     if (!loginUser.isAdmin) {
/* 45 */       super.showErrorMessage(response, "只有管理员才有权限更新部门信息");
/* 46 */       return;
/*    */     }
/*    */ 
/* 49 */     String groupName = Util.getURLParameter(request
/* 50 */       .getParameter("groupName"));
/* 51 */     GroupManager manager = new GroupManager();
/* 52 */     int result = manager.update(this.id, loginUser.companyId, groupName, 
/* 53 */       loginUser.userId);
/* 54 */     JSONObject jsonObject = new JSONObject();
/* 55 */     if (result > 0)
/*    */     {
/* 57 */       CompanyInfo company = super.getCompany(loginUser.companyId);
/*    */       try {
/* 59 */         company.setGroups(manager.list(loginUser.companyId));
/* 60 */         jsonObject.put("error", "0");
/*    */       } catch (DBException e) {
/* 62 */         jsonObject.put("error", "1");
/* 63 */         logger.warn("update group failed", e);
/*    */       } catch (SQLException e) {
/* 65 */         jsonObject.put("error", "1");
/* 66 */         logger.warn("update group failed", e);
/*    */       }
/*    */     }
/* 69 */     response.setContentType("text/html;charset=utf-8");
/* 70 */     PrintWriter out = response.getWriter();
/* 71 */     out.println(jsonObject);
/* 72 */     out.flush();
/* 73 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.UpdateGroup
 * JD-Core Version:    0.6.1
 */